package object.equalsDemo;

class Student {
    String name;
    int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Student(){

    }

    public Student(String name, int age){
        this.age = age;
        this.name = name;
    }

    @Override
    public boolean equals(Object obj) { //Object obj = stu2
        //
        if (obj instanceof Student) {
//        向下转型 为了调用子类独有的成员
            Student stu = (Student) obj;
            return this.age == stu.age && this.name.equals(stu.name);


        }else {
            return false;
        }
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
